from time import sleep

from selenium import  webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait  # 显示等待
from selenium.webdriver.support import  expected_conditions#
class TestOA:
       driver = None

       def setup_class(self):
           TestOA.driver = webdriver.Chrome()
           TestOA.driver.get("http://localhost/ranzhi/www")

       def teardown_class(self):
           TestOA.driver.quit()

       def setup_method(self):
           TestOA.driver = webdriver.Chrome()

       # 随式等待:在等待时间内整个页面完成加家,则执行代码,否则抛出异常,
       # driver.implicitly_wait(10)#
           TestOA.driver.get("http://localhost/ranzhi/www")

       def teardown_method(self):
           TestOA.driver.quit()


       def test_login_success(self):
           try:
               TestOA.driver.maximize_window()
               sleep(2)
               TestOA.driver.find_element(By.ID, "account").send_keys("admin")
               sleep(2)
               TestOA.driver.find_element(By.ID, "password").send_keys("123456")
               sleep(2)
               TestOA.driver.find_element(By.ID, "submit").click()
               sleep(5)
               text = TestOA.driver.find_element(By.LINK_TEXT, "签退").text
               assert text == "签退","登录失败"
           except Exception as e:
               print(f"An error occurred: {e}")
               raise
           # Test0A.driver.guit()





# TestOA.driver.guit()